﻿using Common.Exceptions;
using Microsoft.AspNetCore.Mvc;
using OpenIddict.Client;
using ProductService.Services;
using ProductService.Services.Dtos;
using Servicecomb.Saga.Omega.Abstractions.Transaction;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;

namespace ProductService.Controllers;

[Route("api/productservice/[action]")]
public class ProductController : AbpController
{
    public IProductService ProductService { get; set; }

    public OpenIddictClientService _clientService { get; set; }

    public ProductController()
    {

    }

    [HttpPost]
    //[SagaStart] //1、创建事务【开启事务】
    public async Task<ProductDto> CreateAsync(ProductDto dto)
    {
        var x = await ProductService.CreateAsync(dto);
        return x;
    }

    [HttpDelete]
    public async Task DeleteAsync(Guid id)
    {
        await ProductService.DeleteAsync(id);
    }

    [HttpGet]
    public async Task<ProductDto> GetAsync(Guid id)
    {
        return await ProductService.GetAsync(id);
    }

    [HttpPost]
    public async Task<PagedResultDto<ProductDto>> GetListAsync(PagedAndSortedResultRequestDto input)
    {
        //throw new Exception("未查询到相关信息");
        //throw new CommonException("ydt11111", "未查询到相关信息");
        return await ProductService.GetListAsync(input);
    }

    [HttpPut]
    public async Task<ProductDto> UpdateAsync(Guid id, ProductDto input)
    {
        return await ProductService.UpdateAsync(id, input);
    }
}
